/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package de.jadehs.cosima.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import de.jadehs.cosima.CosimaPackage;
import de.jadehs.cosima.State;
import de.jadehs.cosima.StatesRegister;
import de.jadehs.cosima.Tape;
import de.jadehs.cosima.Transition;
import de.jadehs.cosima.TransitionsTable;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Transitions Table</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link de.jadehs.cosima.impl.TransitionsTableImpl#getTransitions <em>Transitions</em>}</li>
 *   <li>{@link de.jadehs.cosima.impl.TransitionsTableImpl#getTape <em>Tape</em>}</li>
 *   <li>{@link de.jadehs.cosima.impl.TransitionsTableImpl#getActiveState <em>Active State</em>}</li>
 *   <li>{@link de.jadehs.cosima.impl.TransitionsTableImpl#getStates <em>States</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class TransitionsTableImpl extends ProgramImpl implements TransitionsTable {
	/**
	 * The cached value of the '{@link #getTransitions() <em>Transitions</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTransitions()
	 * @generated
	 * @ordered
	 */
	protected EList<Transition> transitions;

	/**
	 * The cached value of the '{@link #getTape() <em>Tape</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTape()
	 * @generated
	 * @ordered
	 */
	protected Tape tape;

	/**
	 * The cached value of the '{@link #getActiveState() <em>Active State</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getActiveState()
	 * @generated
	 * @ordered
	 */
	protected State activeState;

	/**
	 * The cached value of the '{@link #getStates() <em>States</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStates()
	 * @generated
	 * @ordered
	 */
	protected StatesRegister states;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected TransitionsTableImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CosimaPackage.Literals.TRANSITIONS_TABLE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Transition> getTransitions() {
		if (transitions == null) {
			transitions = new EObjectContainmentEList<Transition>(Transition.class, this, CosimaPackage.TRANSITIONS_TABLE__TRANSITIONS);
		}
		return transitions;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Tape getTape() {
		if (tape != null && tape.eIsProxy()) {
			InternalEObject oldTape = (InternalEObject)tape;
			tape = (Tape)eResolveProxy(oldTape);
			if (tape != oldTape) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CosimaPackage.TRANSITIONS_TABLE__TAPE, oldTape, tape));
			}
		}
		return tape;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Tape basicGetTape() {
		return tape;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTape(Tape newTape) {
		Tape oldTape = tape;
		tape = newTape;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CosimaPackage.TRANSITIONS_TABLE__TAPE, oldTape, tape));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public State getActiveState() {
		if (activeState != null && activeState.eIsProxy()) {
			InternalEObject oldActiveState = (InternalEObject)activeState;
			activeState = (State)eResolveProxy(oldActiveState);
			if (activeState != oldActiveState) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CosimaPackage.TRANSITIONS_TABLE__ACTIVE_STATE, oldActiveState, activeState));
			}
		}
		return activeState;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public State basicGetActiveState() {
		return activeState;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setActiveState(State newActiveState) {
		State oldActiveState = activeState;
		activeState = newActiveState;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CosimaPackage.TRANSITIONS_TABLE__ACTIVE_STATE, oldActiveState, activeState));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public StatesRegister getStates() {
		if (states != null && states.eIsProxy()) {
			InternalEObject oldStates = (InternalEObject)states;
			states = (StatesRegister)eResolveProxy(oldStates);
			if (states != oldStates) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CosimaPackage.TRANSITIONS_TABLE__STATES, oldStates, states));
			}
		}
		return states;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public StatesRegister basicGetStates() {
		return states;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStates(StatesRegister newStates) {
		StatesRegister oldStates = states;
		states = newStates;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CosimaPackage.TRANSITIONS_TABLE__STATES, oldStates, states));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CosimaPackage.TRANSITIONS_TABLE__TRANSITIONS:
				return ((InternalEList<?>)getTransitions()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CosimaPackage.TRANSITIONS_TABLE__TRANSITIONS:
				return getTransitions();
			case CosimaPackage.TRANSITIONS_TABLE__TAPE:
				if (resolve) return getTape();
				return basicGetTape();
			case CosimaPackage.TRANSITIONS_TABLE__ACTIVE_STATE:
				if (resolve) return getActiveState();
				return basicGetActiveState();
			case CosimaPackage.TRANSITIONS_TABLE__STATES:
				if (resolve) return getStates();
				return basicGetStates();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CosimaPackage.TRANSITIONS_TABLE__TRANSITIONS:
				getTransitions().clear();
				getTransitions().addAll((Collection<? extends Transition>)newValue);
				return;
			case CosimaPackage.TRANSITIONS_TABLE__TAPE:
				setTape((Tape)newValue);
				return;
			case CosimaPackage.TRANSITIONS_TABLE__ACTIVE_STATE:
				setActiveState((State)newValue);
				return;
			case CosimaPackage.TRANSITIONS_TABLE__STATES:
				setStates((StatesRegister)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CosimaPackage.TRANSITIONS_TABLE__TRANSITIONS:
				getTransitions().clear();
				return;
			case CosimaPackage.TRANSITIONS_TABLE__TAPE:
				setTape((Tape)null);
				return;
			case CosimaPackage.TRANSITIONS_TABLE__ACTIVE_STATE:
				setActiveState((State)null);
				return;
			case CosimaPackage.TRANSITIONS_TABLE__STATES:
				setStates((StatesRegister)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CosimaPackage.TRANSITIONS_TABLE__TRANSITIONS:
				return transitions != null && !transitions.isEmpty();
			case CosimaPackage.TRANSITIONS_TABLE__TAPE:
				return tape != null;
			case CosimaPackage.TRANSITIONS_TABLE__ACTIVE_STATE:
				return activeState != null;
			case CosimaPackage.TRANSITIONS_TABLE__STATES:
				return states != null;
		}
		return super.eIsSet(featureID);
	}

} //TransitionsTableImpl
